package com.taikang.hmp.hbusiness.doctor.diabeteslife.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.doctor.diabeteslife.service.ISugarLifeService;
import com.taikang.hmp.hbusiness.doctor.diabeteslife.util.SugarLifeService;

/**
 * ClassName: SugarLifeAction
 * @Description: 甜蜜人生action
 * @author sunyanming
 * @date 2016年3月22日
 */
public class SugarLifeAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private ISugarLifeService sugarLifeService;
	
	public ISugarLifeService getSugarLifeService() {
		return sugarLifeService;
	}
	public void setSugarLifeService(ISugarLifeService sugarLifeService) {
		this.sugarLifeService = sugarLifeService;
	}
	private static Logger logger = LoggerFactory.getLogger(SugarLifeAction.class);
	@Override
	public String executeAction() {
		if ("login".equals(requestDto.getMethod())){
			logger.info("--【泰康医生登陆高糖】: login method --");
			return login();
		}else if ("saveSugar".equals(requestDto.getMethod())){
			logger.info("--【保存血糖】: saveSugar method --");
			return saveSugar();
		}else if ("getSugarList".equals(requestDto.getMethod())){
			logger.info("--【获取血糖测量列表】: getSugarList method --");
			return getSugarList();
		}else if ("delSugarList".equals(requestDto.getMethod())){
			logger.info("--【删除血糖测量列表】: delSugarList method --");
			return delSugarList();
		}else if ("showCalendar".equals(requestDto.getMethod())){
			logger.info("--【示例假数据日历显示】: showCalendar method --");
			return showCalendar();
		}else {
			throw new TKException("【no support method】:" + requestDto.getMethod());
		}
	}
	/**
	 * @Description: 示例假数据给前台显示
	 * @param @return  
	 * @return String  
	 */
	private String showCalendar() {
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		List<Dto> list = sugarLifeService.getShowCalendar(paramDto);
		Dto dto = new BaseDto();
		dto.put("resultlist", list);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * @Description: 删除血糖列表
	 * @param @return  
	 * @return String  
	 */
	private String delSugarList() {
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		Dto delDto = SugarLifeService.delSugarList("diabetes", requestDto);
		Dto dto = new BaseDto();
		dto.put("resultlist", delDto);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * @Description: 获取血糖列表
	 * @param @return
	 * @return String  
	 */
	private String getSugarList() {
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		Dto sugarlist = SugarLifeService.getSugarList("diabetes", requestDto);
		responseDto.pushResultDto(sugarlist);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * @Description: 保存血糖测量值
	 * @param @return  
	 * @return String  
	 */
	private String saveSugar() {
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		Dto saveDto = SugarLifeService.saveSugar("diabetes", requestDto);
		Dto dto = new BaseDto();
		dto.put("resultlist", saveDto);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * @Description: 泰康医生登陆高糖
	 * @param @return  
	 * @return String  
	 */
	private String login() {
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		Dto loginDto = SugarLifeService.getlogin("diabetes", requestDto);
		responseDto.pushResultDto(loginDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
}
